package com.dreamchaser.book.servlet;

import com.dreamchaser.book.entity.User;
import com.dreamchaser.book.service.UserService;
import com.dreamchaser.book.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Dreamchaser
 */
public class UserServlet extends HttpServlet {
    UserService userService=new UserServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String account=req.getParameter("account");
        String pwd=req.getParameter("pwd");
        User user=userService.login(account,pwd);
        if (user==null){
            resp.getOutputStream().write("账号或者密码不正确，请重新输入！".getBytes());
        }else {
            req.getSession().setAttribute("user",user);
            resp.sendRedirect("/index.jsp");
        }
    }
}
